<?php
    require_once( '../constants/lib_paths.php' );
    require_once( '../constants/db_constants.php' );
    require_once( '../classes/dbaccess.php' );
    require_once( '../classes/membership.php' );
    
    $member = new Membership();
    $member->check_session();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Futura Web OS</title>

    <link rel="stylesheet" type="text/css" href="<?php echo  EXT_STYLE ?>" />
    <link rel="stylesheet" type="text/css" href="<?php echo  EXT_STYLE_GRAY ?>" />

    <link rel="stylesheet" type="text/css" href="<?php echo  ROOT ?>css/desktop.css" />
    <!-- GC -->
 	<!-- LIBS -->
 	<script type="text/javascript" src="<?php echo  EXT_ADAPTER ?>"></script>
 	<!-- ENDLIBS -->

    <script type="text/javascript" src="<?php echo  EXT_BASE ?>"></script>

    <!-- DESKTOP -->
    <script type="text/javascript" src="<?php echo  EXT_STARTMENU ?>"></script>
    <script type="text/javascript" src="<?php echo  EXT_TASKBAR ?>"></script>
    <script type="text/javascript" src="<?php echo  EXT_DESKTOP ?>"></script>
    <script type="text/javascript" src="<?php echo  EXT_APP ?>"></script>
    <script type="text/javascript" src="<?php echo  EXT_MODULE ?>"></script>

	<!-- OS Features -->
	<script type="text/javascript" src="<?php echo  OS_DIALOGS ?>"></script>
    <?php
		$appnames = "";
        $db = new DBAccess();
        $query = "SELECT * FROM apps";
        $db->setQuery($query);
        $db->executeQuery();
        while($v = $db->fetchRow()):	
    ?>
    <script type ="text/javascript" src ="<?php echo ROOT . $v[2];$appnames .= "new ". $v[1] . "(), " ?>">
    </script>
    <?php endwhile; ?>
    
    <?php 
        $file = fopen("desktop.js","w") or exit("Unable to open file!");
        $top = <<<TOP
// Desktop Configuration
FuturaDesktop = new Ext.app.App({
init: function() {
Ext.QuickTips.init();
},

// This is where the apps are loaded
getModules: function() {
return [
TOP;
        
        $bottom = <<<EOF
		];
},

// Start menu configuration
getStartConfig: function(){
		return {
				title: 'Futura OS',
				iconCls: 'user',
				toolItems: [
						{
								text: 'Logout',
								iconCls: 'logout',
								handler: function() { window.location = "../logout.php"; },
								scope: this
						}
				]
		};
}
});
EOF;
        fwrite($file,$top);
        fwrite($file, substr($appnames, 0, strlen($appnames) - 2));
        fwrite($file, $bottom);
        fclose($file);
    ?>
    <script type="text/javascript" src="desktop.js"></script>
</head>
<body scroll="no">
    <div id="x-desktop">
    <dl id="x-shortcuts">
    <?php 
        mysql_select_db('futura');
		$res = mysql_query($query);
        while($v = mysql_fetch_row($res)):
    ?>
        <dt id="<?php echo  strtolower($v[1]); ?>-win-shortcut" class="desktop-icon">
            <a href="#"><img src="<?php echo  ROOT ?>images/icons/<?php echo  strtolower($v[1]); ?>.png" />
            <div><?php echo  $v[1] ?></div></a>
        </dt>
    <?php endwhile; ?>
    </dl>
</div>
<div id="ux-taskbar">
	<div id="ux-taskbar-start"></div>
	<div id="ux-taskbuttons-panel"></div>
	<div class="x-clear"></div>
</div>
</body>
</html>
